<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click="addData">点击增加对象数据</button>
        <h3>向对象里增加方法</h3>
        <ul>
            <li v-for="(val,key,index) of obj">
                值:{{val}}---key:{{key}}---索引{{index}}
            </li>
        </ul>
        <button @click="addData2">点击增加对象数据</button>
        <h3>向对象里增加方法</h3>
        <ul>
            <li v-for="(item,index) of obj">
                {{item}}
            </li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                obj: {
                    title: 'hello world',
                    name: 'zhangsan',
                    age: 17,
                    sex: '男'
                },
                list: [1, 2, 3, 4]
            },
            methods: {
                addData() {
                    Vue.set(this.obj, "skin" + Math.random(), "red")
                },
                addData2() {
                    vm.$set(vm.list, 0, "hello world")
                }
            },
        })
    </script>
</body>

</html>